package com.roshan.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@NamedQueries(value = {
    @NamedQuery(name = "retrieveUserByEmail", query = "from User u where u.email = :email and deleted = false"),
    @NamedQuery(name = "retrieveActiveUserByEmail", query = "from User u where u.email = :email and deleted = false and active = true"),
    @NamedQuery(name = "retrieveUserByUri", query = "from User u where u.uri = :uri and deleted = false"),
    @NamedQuery(name = "retrieveUserByUsername", query = "from User u where u.securityUser.username = :username and deleted = false"),
    @NamedQuery(name = "retrieveActiveUserByUsername", query = "from User u where u.securityUser.username = :username and deleted = false and active = true"),
    @NamedQuery(name = "validateUser", query = "from User u where u.securityUser.username = :username and u.securityUser.password = :password and deleted = false and active = :active")})
@Entity
@Table(name = "USER")
public class User extends BaseDomain<Long> {

    private static final long serialVersionUID = 100L;

    @Column(name = "FIRST_NAME")
    private String firstName;

    @Column(name = "LAST_NAME")
    private String lastName;

    @Column(name = "EMAIL")
    private String email;

    @Column(name = "MOBILE")
    private String mobile;

    @Embedded
    private SecurityUser securityUser;

    @Embedded
    private Address address;

    @Column(name = "CREATED_BY")
    private String createdBy;

    @Column(name = "MODIFIED_BY")
    private String modifiedBy;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "user")
    private List<MfaCredential> mfaCredentials = new ArrayList<MfaCredential>();

    public String getFirstName() {
        return this.firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return this.lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMobile() {
        return this.mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public SecurityUser getSecurityUser() {
        return this.securityUser;
    }

    public void setSecurityUser(SecurityUser securityUser) {
        this.securityUser = securityUser;
    }

    public Address getAddress() {
        return this.address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public String getCreatedBy() {
        return this.createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public String getModifiedBy() {
        return this.modifiedBy;
    }

    public void setModifiedBy(String modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    public List<MfaCredential> getMfaCredentials() {
        return this.mfaCredentials;
    }

    public void setMfaCredentials(List<MfaCredential> mfaCredentials) {
        this.mfaCredentials = mfaCredentials;
    }

}
